package de.tum.in.eist.poll.client.Model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.IdentityType;


@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Lecture implements Serializable {
	/**
	 * 
	 */
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String encodedKey;
	
	@Persistent
	private String subject;
	@Persistent
	private String lecturer;
	@Persistent
	private String date;
	@Persistent
	private boolean open;
	@NotPersistent
	private boolean alreadyVoted;
	
	@NotPersistent
	private ArrayList<Feedback> feedbacks;
	
	@SuppressWarnings("unused")
	private Lecture() {
		
	}
	
	public Lecture(String subject, String lecturer, boolean open) {
		this.subject = subject;
		this.lecturer = lecturer;
		Date date = new Date();
		this.date = date.toString();
		this.open = open;
		this.feedbacks = new ArrayList<Feedback>();
		this.alreadyVoted = false;
	}
	
//	public Lecture(String subject, String lecturer, String date, boolean open) {
//		this(subject, lecturer, date, open);
//	}
	
	public String getEncodedKey() {
		return encodedKey;
	}
	
	public String getLecturer() {
		return lecturer;
	}

	public String getDate() {
		return date;
	}

	public boolean getOpen() {
		return open;
	}
	
	public void setOpen(boolean b) {
		this.open = b;
	}
	
	public String getSubject() {
		return subject;
	}
	
	public boolean getAlreadyVoted() {
		return alreadyVoted;
	}
	
	public void setAlreadyVoted(boolean b) {
		this.alreadyVoted = b;
	}
	
	public ArrayList<Feedback> getFeedbacks() {
		return feedbacks;
	}
	
	public void setFeedbacks(List<Feedback> newList) {
		ArrayList<Feedback> fbList = new ArrayList<Feedback>();
		fbList.addAll(newList);
		this.feedbacks = fbList;
	}
	
	public void setFeedbacks(Feedback[] fbArr) {
		ArrayList<Feedback> fbList = new ArrayList<Feedback>();
		
		for (int i = 0; i < fbArr.length; i++) {
			fbList.add(fbArr[i]);
		}
		
		this.feedbacks = fbList;
	}
}

